﻿/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * The Original Code is tyzoh.jp code.
 *
 * The Initial Developer of the Original Code is Kazutaka Kurihara.
 * Portions created by the Initial Developer are Copyright (C) 2007
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * ***** END LICENSE BLOCK ***** */
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;

namespace Qurihara
{
	/// <summary>
	/// ManagerForm の概要の説明です。
	/// </summary>
	public class ManagerForm : System.Windows.Forms.Form, MRUManager.IMRUClient, DragDropManager.IDropFileTarget, IMessageFilter
	{

		/// <summary>
		/// 必要なデザイナ変数です。
		/// </summary>
		///

		//public string registryPath = "Software\\Qurihara\\Kotodama";  // Registry path to keep persistent data
		public MRUManager.FileMRUManager mruManager;      // MRU list manager
		public ToolBarDock.ToolBarManager toolBarManager; // toolbar manager
		public QBasic.FocusManager focusManager; // focus manager;
		public Hashtable environmentTable;

		public ManagerMain main = null;
        //public Host.PluginServices.Kotodama_ kotodama_= null;
        public Kotodama_ kotodama_ = null;

		public System.Windows.Forms.MainMenu mainMenu1;
		public System.Windows.Forms.MenuItem menuItem5;
		public System.Windows.Forms.MenuItem menuItem11;
		public System.Windows.Forms.MenuItem menuItem8;
		public System.Windows.Forms.MenuItem menuItem13;
		public System.Windows.Forms.MenuItem menuItem20;
		public System.Windows.Forms.MenuItem menuItem21;
		public System.Windows.Forms.MenuItem menuItem22;
		public System.Windows.Forms.MenuItem menuItem4;
		public System.Windows.Forms.MenuItem menuItem6;
        public System.Windows.Forms.OpenFileDialog openFileDialog;
		private System.Windows.Forms.MenuItem menuItem51;
		private System.Windows.Forms.MenuItem menuItem52;
		private System.Windows.Forms.MenuItem menuItem53;
		private System.Windows.Forms.MenuItem menuItem54;
		private System.Windows.Forms.MenuItem menuItem55;
		private System.Windows.Forms.MenuItem menuItem56;
        private System.Windows.Forms.MenuItem menuItem57;
		private System.Windows.Forms.MenuItem menuItem62;
		public System.Windows.Forms.MenuItem menuItem1;
		public System.Windows.Forms.MenuItem menuItem17;
		public System.Windows.Forms.MenuItem menuItem18;
		public System.Windows.Forms.MenuItem MRUMenuItem;
        public System.Windows.Forms.MenuItem menuItem23;
		public System.Windows.Forms.MenuItem prezen_pack;
		private System.Windows.Forms.MenuItem menuItem58;
		private System.Windows.Forms.MenuItem menuItem63;
		public System.Windows.Forms.MenuItem DoubleBufferCheckButton;
        private System.Windows.Forms.MenuItem menuItemPlugIn;
		public System.Windows.Forms.MenuItem menuItemToolBars;
		private System.Windows.Forms.MenuItem menuItem7;
        private MenuItem menuItem3;
        private MenuItem menuItem9;
        private MenuItem menuItem10;
        private MenuItem menuItem12;
        public SaveFileDialog saveFileDialog;
		private System.ComponentModel.IContainer components = null;
        public SplitContainer splitContainerMain;
        public TabControl tabControlMembers;
        private TabPage tabPageAll;
        public ListView listViewScreens;
        private TabControl tabControlScreens;
        private TabPage tabPage1;
        private TabPage tabPageAllTemp;

        public DoubleBufferedPanel panelCanvas;

		public ManagerForm()
		{
            Application.EnableVisualStyles();

			//
			// Windows フォーム デザイナ サポートに必要です。
			//

			InitializeComponent();

            panelCanvas = new DoubleBufferedPanel();
            this.panelCanvas.BackColor = System.Drawing.SystemColors.Window;
            this.panelCanvas.Location = new System.Drawing.Point(315, 128);
            this.panelCanvas.Name = "panelCanvas";
            this.panelCanvas.Size = new System.Drawing.Size(381, 253);
            this.panelCanvas.BorderStyle = BorderStyle.FixedSingle;// .Fixed3D;
            this.panelCanvas.TabIndex = 17;
            this.panelCanvas.Paint += new System.Windows.Forms.PaintEventHandler(this.panelCanvas_Paint);
            //this.Controls.Add(this.panelCanvas);
            //this.splitContainerMain.Panel2.Controls.Add(this.panelCanvas);
            this.tabPageAll.Controls.Add(this.panelCanvas);


            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.DoubleBuffer, false);

			main = new ManagerMain(this);

			toolBarManager = new ToolBarDock.ToolBarManager(this,this);
			focusManager = new Qurihara.QBasic.FocusManager();
			focusManager.EnterFromInternalEventHandler+=new EventHandler(focusManager_EnterFromInternalEventHandler);

			environmentTable = new Hashtable();

			Application.AddMessageFilter(this);

            if (QBasic.Util.IsPropertyTrue("Base.English"))
            {
                //MessageBox.Show("English Mode");
                menuItem1.Text = "File";
                menuItem17.Text = "Strat a new presentation";
                menuItem18.Text = "Load an existing presentation";
                MRUMenuItem.Text = "Most recently used presentations";
                menuItem7.Text = "Save the current presentation";
                //menuItem2.Text = "Save the current presentation and exit";
                menuItem63.Text = "Configurations";
                DoubleBufferCheckButton.Text = "Enable double buffering";
               
 
                menuItem8.Text = "Edit";
                menuItem62.Text = "Redraw";
                menuItemToolBars.Text = "ToolBars";

                menuItem5.Text = "Undo";
                menuItem11.Text = "Redo";

                menuItem9.Text = "Examples";
                menuItem10.Text = "triangles";
                menuItem12.Text = "pear";
            }
		}
		private void LoadPlugin()
		{
			//Host.PluginServices.Kotodama_ k = new Host.PluginServices.Kotodama_(this,this.main.presen,this.main.myInkCollector,this.main.selectedElementList,this.toolBarManager);
			//Host.Global.Plugins.Kotodama = k;
            //kotodama_ = new Host.PluginServices.Kotodama_(this.panelCanvas,this,this.main.presen,this.main.myInkCollector,this.main.selectedElementList,this.toolBarManager,focusManager,environmentTable);
            kotodama_ = new Kotodama_(this.panelCanvas, this, this.main.presen, this.main.myInkCollector, this.main.selectedElementList, this.toolBarManager, focusManager, environmentTable);
            Host.Global.Plugins.Kotodama = kotodama_;

			Host.Global.Plugins.FindPlugins(Application.StartupPath + @"\Plugins");
			// add to menu;
			//Add each plugin to the treeview
			foreach (Host.Types.AvailablePlugin pluginOn in Host.Global.Plugins.AvailablePlugins)
			{
				MenuItem newItem = new MenuItem(pluginOn.Instance.Name);

				// subscribe to item's Click event
				//newItem.Click += new EventHandler(this.OnMRUClicked);

				menuItemPlugIn.MenuItems.Add(newItem);

				newItem.Checked = true;
				newItem.Click += new EventHandler(PlugIn_Click);

				newItem = null;
			}
		}		
		private void PlugIn_Click(object sender, EventArgs e)
		{
			MenuItem item = (MenuItem)sender;
			string name = item.Text;
			Host.Types.AvailablePlugin pluginClicked = Host.Global.Plugins.AvailablePlugins.Find(name);
			if (pluginClicked != null) 
			{
				if(item.Checked)
				{//to invalidate
					pluginClicked.Instance.Dispose();
				}
				else
				{//to validate
					pluginClicked.Instance.Initialize();
				}
				item.Checked = !item.Checked;
			}
			

		}

		public void SetDoubleBuffer(bool b)
		{
			SetStyle(ControlStyles.DoubleBuffer,b);
		}

		/// <summary>
		/// 使用されているリソースに後処理を実行します。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
		/// コード エディタで変更しないでください。
		/// </summary>
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ManagerForm));
            System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
            this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components);
            this.menuItem1 = new System.Windows.Forms.MenuItem();
            this.menuItem17 = new System.Windows.Forms.MenuItem();
            this.menuItem18 = new System.Windows.Forms.MenuItem();
            this.MRUMenuItem = new System.Windows.Forms.MenuItem();
            this.menuItem23 = new System.Windows.Forms.MenuItem();
            this.menuItem7 = new System.Windows.Forms.MenuItem();
            this.prezen_pack = new System.Windows.Forms.MenuItem();
            this.menuItem58 = new System.Windows.Forms.MenuItem();
            this.menuItem63 = new System.Windows.Forms.MenuItem();
            this.DoubleBufferCheckButton = new System.Windows.Forms.MenuItem();
            this.menuItemPlugIn = new System.Windows.Forms.MenuItem();
            this.menuItem3 = new System.Windows.Forms.MenuItem();
            this.menuItem9 = new System.Windows.Forms.MenuItem();
            this.menuItem10 = new System.Windows.Forms.MenuItem();
            this.menuItem12 = new System.Windows.Forms.MenuItem();
            this.menuItem8 = new System.Windows.Forms.MenuItem();
            this.menuItem13 = new System.Windows.Forms.MenuItem();
            this.menuItem20 = new System.Windows.Forms.MenuItem();
            this.menuItem21 = new System.Windows.Forms.MenuItem();
            this.menuItem54 = new System.Windows.Forms.MenuItem();
            this.menuItem55 = new System.Windows.Forms.MenuItem();
            this.menuItem56 = new System.Windows.Forms.MenuItem();
            this.menuItem57 = new System.Windows.Forms.MenuItem();
            this.menuItem22 = new System.Windows.Forms.MenuItem();
            this.menuItem51 = new System.Windows.Forms.MenuItem();
            this.menuItem52 = new System.Windows.Forms.MenuItem();
            this.menuItem53 = new System.Windows.Forms.MenuItem();
            this.menuItem62 = new System.Windows.Forms.MenuItem();
            this.menuItemToolBars = new System.Windows.Forms.MenuItem();
            this.menuItem4 = new System.Windows.Forms.MenuItem();
            this.menuItem5 = new System.Windows.Forms.MenuItem();
            this.menuItem11 = new System.Windows.Forms.MenuItem();
            this.menuItem6 = new System.Windows.Forms.MenuItem();
            this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
            this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
            this.splitContainerMain = new System.Windows.Forms.SplitContainer();
            this.tabControlScreens = new System.Windows.Forms.TabControl();
            this.tabPage1 = new System.Windows.Forms.TabPage();
            this.listViewScreens = new System.Windows.Forms.ListView();
            this.tabControlMembers = new System.Windows.Forms.TabControl();
            this.tabPageAll = new System.Windows.Forms.TabPage();
            this.tabPageAllTemp = new System.Windows.Forms.TabPage();
            this.splitContainerMain.Panel1.SuspendLayout();
            this.splitContainerMain.Panel2.SuspendLayout();
            this.splitContainerMain.SuspendLayout();
            this.tabControlScreens.SuspendLayout();
            this.tabPage1.SuspendLayout();
            this.tabControlMembers.SuspendLayout();
            this.SuspendLayout();
            // 
            // mainMenu1
            // 
            this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItem1,
            this.menuItem8,
            this.menuItem4,
            this.menuItem5,
            this.menuItem11,
            this.menuItem6});
            // 
            // menuItem1
            // 
            this.menuItem1.Index = 0;
            this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItem17,
            this.menuItem18,
            this.MRUMenuItem,
            this.menuItem23,
            this.menuItem7,
            this.prezen_pack,
            this.menuItem58,
            this.menuItem63,
            this.menuItemPlugIn,
            this.menuItem3,
            this.menuItem9});
            this.menuItem1.Text = "ファイル";
            // 
            // menuItem17
            // 
            this.menuItem17.Index = 0;
            this.menuItem17.Text = "新しい白紙";
            this.menuItem17.Click += new System.EventHandler(this.startNewPresen_click);
            // 
            // menuItem18
            // 
            this.menuItem18.Index = 1;
            this.menuItem18.Text = "既存資料の読み込み";
            this.menuItem18.Click += new System.EventHandler(this.loadStartPresen_click);
            // 
            // MRUMenuItem
            // 
            this.MRUMenuItem.Index = 2;
            this.MRUMenuItem.Text = "最近使った資料";
            // 
            // menuItem23
            // 
            this.menuItem23.Index = 3;
            this.menuItem23.Text = "-";
            // 
            // menuItem7
            // 
            this.menuItem7.Index = 4;
            this.menuItem7.Text = "資料を保存";
            this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click);
            // 
            // prezen_pack
            // 
            this.prezen_pack.Index = 5;
            this.prezen_pack.Text = "履歴を消して高速＆低容量保存";
            this.prezen_pack.Click += new System.EventHandler(this.prezen_pack_Click);
            // 
            // menuItem58
            // 
            this.menuItem58.Index = 6;
            this.menuItem58.Text = "-";
            // 
            // menuItem63
            // 
            this.menuItem63.Index = 7;
            this.menuItem63.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.DoubleBufferCheckButton});
            this.menuItem63.Text = "環境設定";
            // 
            // DoubleBufferCheckButton
            // 
            this.DoubleBufferCheckButton.Checked = true;
            this.DoubleBufferCheckButton.Index = 0;
            this.DoubleBufferCheckButton.RadioCheck = true;
            this.DoubleBufferCheckButton.Text = "ダブルバッファリングを有効にする";
            this.DoubleBufferCheckButton.Click += new System.EventHandler(this.DoubleBufferCheckButton_Click);
            // 
            // menuItemPlugIn
            // 
            this.menuItemPlugIn.Index = 8;
            this.menuItemPlugIn.Text = "Plug-In";
            // 
            // menuItem3
            // 
            this.menuItem3.Index = 9;
            this.menuItem3.Text = "-";
            // 
            // menuItem9
            // 
            this.menuItem9.Index = 10;
            this.menuItem9.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItem10,
            this.menuItem12});
            this.menuItem9.Text = "例";
            // 
            // menuItem10
            // 
            this.menuItem10.Index = 0;
            this.menuItem10.Text = "三角形";
            this.menuItem10.Click += new System.EventHandler(this.menuItem10_Click);
            // 
            // menuItem12
            // 
            this.menuItem12.Index = 1;
            this.menuItem12.Text = "梨";
            this.menuItem12.Click += new System.EventHandler(this.menuItem12_Click);
            // 
            // menuItem8
            // 
            this.menuItem8.Index = 1;
            this.menuItem8.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItem13,
            this.menuItem20,
            this.menuItem51,
            this.menuItem62,
            this.menuItemToolBars});
            this.menuItem8.Text = "編集";
            this.menuItem8.Popup += new System.EventHandler(this.menuItem8_Popup);
            // 
            // menuItem13
            // 
            this.menuItem13.Enabled = false;
            this.menuItem13.Index = 0;
            this.menuItem13.Text = "複写";
            this.menuItem13.Visible = false;
            this.menuItem13.Click += new System.EventHandler(this.CopyAndPaste_click);
            // 
            // menuItem20
            // 
            this.menuItem20.Enabled = false;
            this.menuItem20.Index = 1;
            this.menuItem20.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItem21,
            this.menuItem22});
            this.menuItem20.Text = "整形";
            this.menuItem20.Visible = false;
            // 
            // menuItem21
            // 
            this.menuItem21.Index = 0;
            this.menuItem21.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItem54,
            this.menuItem55,
            this.menuItem56,
            this.menuItem57});
            this.menuItem21.Text = "配置";
            // 
            // menuItem54
            // 
            this.menuItem54.Index = 0;
            this.menuItem54.Text = "縦に軸をそろえる";
            this.menuItem54.Click += new System.EventHandler(this.menuItem54_Click);
            // 
            // menuItem55
            // 
            this.menuItem55.Index = 1;
            this.menuItem55.Text = "横に軸をそろえる";
            this.menuItem55.Click += new System.EventHandler(this.menuItem55_Click);
            // 
            // menuItem56
            // 
            this.menuItem56.Index = 2;
            this.menuItem56.Text = "縦に等間隔配置";
            this.menuItem56.Click += new System.EventHandler(this.menuItem56_Click);
            // 
            // menuItem57
            // 
            this.menuItem57.Index = 3;
            this.menuItem57.Text = "横に等間隔配置";
            this.menuItem57.Click += new System.EventHandler(this.menuItem57_Click);
            // 
            // menuItem22
            // 
            this.menuItem22.Index = 1;
            this.menuItem22.Text = "大きさをそろえる";
            this.menuItem22.Click += new System.EventHandler(this.formBySize_click);
            // 
            // menuItem51
            // 
            this.menuItem51.Enabled = false;
            this.menuItem51.Index = 2;
            this.menuItem51.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItem52,
            this.menuItem53});
            this.menuItem51.Text = "グループ化";
            this.menuItem51.Visible = false;
            // 
            // menuItem52
            // 
            this.menuItem52.Index = 0;
            this.menuItem52.Text = "グループ化";
            this.menuItem52.Click += new System.EventHandler(this.menuItem52_Click);
            // 
            // menuItem53
            // 
            this.menuItem53.Index = 1;
            this.menuItem53.Text = "グループ解除";
            this.menuItem53.Click += new System.EventHandler(this.menuItem53_Click);
            // 
            // menuItem62
            // 
            this.menuItem62.Index = 3;
            this.menuItem62.Text = "再描画";
            this.menuItem62.Click += new System.EventHandler(this.menuItem62_Click);
            // 
            // menuItemToolBars
            // 
            this.menuItemToolBars.Index = 4;
            this.menuItemToolBars.Text = "ツールバー";
            // 
            // menuItem4
            // 
            this.menuItem4.Enabled = false;
            this.menuItem4.Index = 2;
            this.menuItem4.Text = "";
            // 
            // menuItem5
            // 
            this.menuItem5.Enabled = false;
            this.menuItem5.Index = 3;
            this.menuItem5.Text = "戻る";
            this.menuItem5.Click += new System.EventHandler(this.UnDo);
            // 
            // menuItem11
            // 
            this.menuItem11.Enabled = false;
            this.menuItem11.Index = 4;
            this.menuItem11.Text = "進む";
            this.menuItem11.Click += new System.EventHandler(this.ReDo);
            // 
            // menuItem6
            // 
            this.menuItem6.Enabled = false;
            this.menuItem6.Index = 5;
            this.menuItem6.Text = "";
            // 
            // openFileDialog
            // 
            this.openFileDialog.AddExtension = false;
            // 
            // splitContainerMain
            // 
            this.splitContainerMain.Dock = System.Windows.Forms.DockStyle.Fill;
            this.splitContainerMain.Location = new System.Drawing.Point(0, 0);
            this.splitContainerMain.Name = "splitContainerMain";
            // 
            // splitContainerMain.Panel1
            // 
            this.splitContainerMain.Panel1.Controls.Add(this.tabControlScreens);
            // 
            // splitContainerMain.Panel2
            // 
            this.splitContainerMain.Panel2.Controls.Add(this.tabControlMembers);
            this.splitContainerMain.Size = new System.Drawing.Size(746, 367);
            this.splitContainerMain.SplitterDistance = 160;
            this.splitContainerMain.TabIndex = 17;
            // 
            // tabControlScreens
            // 
            this.tabControlScreens.Controls.Add(this.tabPage1);
            this.tabControlScreens.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tabControlScreens.Location = new System.Drawing.Point(0, 0);
            this.tabControlScreens.Name = "tabControlScreens";
            this.tabControlScreens.SelectedIndex = 0;
            this.tabControlScreens.Size = new System.Drawing.Size(160, 367);
            this.tabControlScreens.TabIndex = 0;
            // 
            // tabPage1
            // 
            this.tabPage1.Controls.Add(this.listViewScreens);
            this.tabPage1.Location = new System.Drawing.Point(4, 21);
            this.tabPage1.Name = "tabPage1";
            this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
            this.tabPage1.Size = new System.Drawing.Size(152, 342);
            this.tabPage1.TabIndex = 0;
            this.tabPage1.Text = "Screens";
            this.tabPage1.UseVisualStyleBackColor = true;
            // 
            // listViewScreens
            // 
            this.listViewScreens.Dock = System.Windows.Forms.DockStyle.Fill;
            this.listViewScreens.Location = new System.Drawing.Point(3, 3);
            this.listViewScreens.MultiSelect = false;
            this.listViewScreens.Name = "listViewScreens";
            this.listViewScreens.Size = new System.Drawing.Size(146, 336);
            this.listViewScreens.TabIndex = 0;
            this.listViewScreens.UseCompatibleStateImageBehavior = false;
            // 
            // tabControlMembers
            // 
            this.tabControlMembers.Controls.Add(this.tabPageAll);
            this.tabControlMembers.Controls.Add(this.tabPageAllTemp);
            this.tabControlMembers.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tabControlMembers.Location = new System.Drawing.Point(0, 0);
            this.tabControlMembers.Multiline = true;
            this.tabControlMembers.Name = "tabControlMembers";
            this.tabControlMembers.SelectedIndex = 0;
            this.tabControlMembers.Size = new System.Drawing.Size(582, 367);
            this.tabControlMembers.TabIndex = 0;
            // 
            // tabPageAll
            // 
            this.tabPageAll.BackColor = System.Drawing.Color.White;
            this.tabPageAll.Location = new System.Drawing.Point(4, 21);
            this.tabPageAll.Name = "tabPageAll";
            this.tabPageAll.Padding = new System.Windows.Forms.Padding(3);
            this.tabPageAll.Size = new System.Drawing.Size(574, 342);
            this.tabPageAll.TabIndex = 0;
            this.tabPageAll.Text = "All";
            this.tabPageAll.UseVisualStyleBackColor = true;
            // 
            // tabPageAllTemp
            // 
            this.tabPageAllTemp.Location = new System.Drawing.Point(4, 21);
            this.tabPageAllTemp.Name = "tabPageAllTemp";
            this.tabPageAllTemp.Size = new System.Drawing.Size(574, 299);
            this.tabPageAllTemp.TabIndex = 1;
            this.tabPageAllTemp.Text = "All(Temp.)";
            this.tabPageAllTemp.UseVisualStyleBackColor = true;
            // 
            // ManagerForm
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
            this.BackColor = System.Drawing.Color.White;
            this.ClientSize = new System.Drawing.Size(746, 367);
            this.Controls.Add(this.splitContainerMain);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Menu = this.mainMenu1;
            this.Name = "ManagerForm";
            this.Text = ((string)(configurationAppSettings.GetValue("KotodamaForm.Text", typeof(string))));
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            this.Paint += new System.Windows.Forms.PaintEventHandler(this.KotodamaForm_Paint);
            this.Closing += new System.ComponentModel.CancelEventHandler(this.KotodamaForm_Closing);
            this.Load += new System.EventHandler(this.KotodamaForm_Load);
            this.splitContainerMain.Panel1.ResumeLayout(false);
            this.splitContainerMain.Panel2.ResumeLayout(false);
            this.splitContainerMain.ResumeLayout(false);
            this.tabControlScreens.ResumeLayout(false);
            this.tabPage1.ResumeLayout(false);
            this.tabControlMembers.ResumeLayout(false);
            this.ResumeLayout(false);

		}
		#endregion

		#region IMRUClient interface implementation
		/// <summary>
		/// IMRUClient interface implementation - open file clicked from MRU list.
		/// </summary>
		/// <param name="fileName">File name</param>
		public bool OpenMRUFile(string fileName)
		{
			if(System.IO.File.Exists(fileName))
			{
                if (main.SaveIfUnsaved())
                {
                    main.LoadStartPresen(fileName);
                    return true;
                }
			}
			return false;
		}

		#endregion 

		#region IDropFileTarget interface implement
		public void FilesDropped(Point p,Array a,string d)
		{
			//main.FilesDropped(p,a);
			kotodama_.FireFormFilesDrop(p,a,d);
			this.Invalidate();
		}
		#endregion

		#region IMessageFilter メンバ

		const int WM_KEYDOWN = 0x100;
		const int WM_KEYUP = 0x101; 
		
		public bool PreFilterMessage(ref Message m) 
		{
			if(m.Msg == WM_KEYDOWN) 
			{
				Keys keyCode = (Keys)(int)m.WParam & Keys.KeyCode;
				kotodama_.FireKeyboardDown(keyCode);
			} 
			else if(m.Msg == WM_KEYUP) 
			{
				Keys keyCode = (Keys)(int)m.WParam & Keys.KeyCode;
				kotodama_.FireKeyboardUp(keyCode);
			}
			return false;
		}

		#endregion

		//** 以後はForm系のイベントハンドラ
		//** システム系

		private void KotodamaForm_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
            ////int i = System.DateTime.Now.Millisecond;

            //e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            ////main.Paint(sender,e,false);
            //main.Paint(e.Graphics,false);

            ////int j = System.DateTime.Now.Millisecond - i;
            ////System.Diagnostics.Debug.WriteLine("finish:" +j.ToString());

            ////if (this.ShowingWindowCheckButton.Checked) showingForm.Invalidate();
		}

		//** メニューアイテム系
		private void menuItem7_Click(object sender, System.EventArgs e)
		{
			main.FormMenuSavePresen_Click(sender,e);		
		}

		private void ReDo(object sender, System.EventArgs e)
		{
			main.FormMenuReDo_Click(sender,e);
		}
		private void UnDo(object sender, System.EventArgs e)
		{
			main.FormMenuUnDo_Click(sender,e);
		}
	
		private void loadStartPresen_click(object sender, System.EventArgs e)
		{
            if (main.SaveIfUnsaved())
            {
                main.FormMenuLoadStartPresen_Click(sender, e);
            }
		}

		private void startNewPresen_click(object sender, System.EventArgs e)
		{
            if (main.SaveIfUnsaved())
            {
                main.FormMenuStartNewPresen_Click(sender, e,false);
            }
		}

		private void CopyAndPaste_click(object sender, System.EventArgs e)
		{
			main.FormMenuCopyAndPaste_Click(sender,e);
		}

		private void formBySize_click(object sender, System.EventArgs e)
		{
			main.FormMenuFormBySize_Click(sender,e);
		}

		private void prezen_pack_Click(object sender, System.EventArgs e)
		{
            main.FormMenuSaveSimpleXML();
		}

		private void KotodamaForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			main.Closing(sender,e);
		}

		private void KotodamaForm_Load(object sender, System.EventArgs e)
		{
			main.Load(sender,e);

			// load defaut toolbar
            //toolBarDefault.Text = "Default";
            //toolBarManager.AddControl(toolBarDefault,DockStyle.None);


			LoadPlugin();
			SetDoubleBuffer(true);
			focusManager.AddControlRecursive(this);

            this.panelCanvas.SendToBack();
		}
		private void menuItem52_Click(object sender, System.EventArgs e)
		{
			main.FormMenuMakeGroup_Click(sender,e);
		}

		private void menuItem53_Click(object sender, System.EventArgs e)
		{
			main.FormMenuReleaseGroup_Click(sender,e);
		}

		private void menuItem54_Click(object sender, System.EventArgs e)
		{
			main.FormMenuUnifyVerticalAxis_Click(sender,e);
		}

		private void menuItem55_Click(object sender, System.EventArgs e)
		{
			main.FormMenuUnifyHorizontalAxis_Click(sender,e);
		}

		private void menuItem56_Click(object sender, System.EventArgs e)
		{
			main.FormMenuAlignmentVerticalAxis_Click(sender,e);
		}

		private void menuItem57_Click(object sender, System.EventArgs e)
		{
			main.FormMenuAlignmentHorizontalAxis_Click(sender,e);
		}

		private void menuItem62_Click(object sender, System.EventArgs e)
		{
			main.FormMenuReDraw_Click(sender,e);
		}

		private void DoubleBufferCheckButton_Click(object sender, System.EventArgs e)
		{
			main.FormMenuDoubleBufferCheckButton_Click(sender,e);
		}

		// toolbar information update
		private void menuItem8_Popup(object sender, System.EventArgs e)
		{
			main.FormMenuToolBarsPopUp(sender,e);
		}

//		private void KotodamaForm_MouseEnter(object sender, System.EventArgs e)
//		{
//			//ツールバーにフォーカスを取られない対策。
//			this.Activate();
//		}

		private void focusManager_EnterFromInternalEventHandler(object sender, EventArgs e)
		{
			if(sender.Equals(this))
			{
				//ツールバーにフォーカスを取られない対策。
				this.Activate();
			}
		}

        private void menuItem10_Click(object sender, EventArgs e)
        {
            if (main.SaveIfUnsaved())
            {
                main.LoadExample("triangles");
            }
        }

        private void menuItem12_Click(object sender, EventArgs e)
        {
            if (main.SaveIfUnsaved())
            {
                main.LoadExample("pear");
            }
        }

        private void panelCanvas_Paint(object sender, PaintEventArgs e)
        {
            //int i = System.DateTime.Now.Millisecond;

            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            //main.Paint(sender,e,false);
            main.Paint(e.Graphics, false);

            //int j = System.DateTime.Now.Millisecond - i;
            //System.Diagnostics.Debug.WriteLine("finish:" +j.ToString());

            //if (this.ShowingWindowCheckButton.Checked) showingForm.Invalidate();

        }
	}
}
